package com.jrew.gae.wcs.spring.controllers;

import java.util.ArrayList;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.configuration.PropertiesConfiguration;
import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;

import com.jrew.gae.wcs.constants.AppConstant;

/**
 *
 */
public class GetLevelsController extends AbstractController {
		
	/**
	 * 
	 */
	private String viewName;
	private final int levelsNumber = 15; 
	
	@Override
	protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
		ModelAndView modelAndView = new ModelAndView(viewName);
		modelAndView.addObject(AppConstant.LEVELS_NUMBER, levelsNumber);
		modelAndView.addObject(AppConstant.LANGUAGES, getLanguages());
		return modelAndView;
	}

	/**
	 * @return
	 */
	public String getViewName() {
		return viewName;
	}

	/**
	 * @param viewName
	 */
	public void setViewName(String viewName) {
		this.viewName = viewName;
	}
	
	/**
	 * @return
	 */
	public ArrayList<String> getLanguages(){
		ArrayList<String> lang = new ArrayList<String>(5);
		
		/**
		try{
			PropertiesConfiguration config = new PropertiesConfiguration(AppConstant.APP_PROPS_FILE_NAME);
			String allLanguages = config.getString(AppConstant.LANGUAGES);
			String[] languages = allLanguages.split(","); 
			for(int i = 0; i < languages.length; i++){
				lang.add(languages[i]);
			}
		} catch (Exception e) {
			// TODO: handle exception
		}
		**/
		
		return lang;
	}
}
